<template>
    <div>
        <h3>优惠券添加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">优惠券名称</td>
                    <td>
                        <input type="text" v-model="Info.CouponName">
                    </td>
                </tr>
                <tr>
                    <td align="right">优惠券类型</td>
                    <td>
                        <input type="text" v-model="Info.CouponType">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="添加" @click="add" class="btn btn-primary"></td>
                </tr>
                
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
import router from '@/router';
const Route = useRoute();
const Router = useRouter();

let Info:any=reactive({
  "CouponName": "",
  "CouponType": "",
})
const add=()=>{
    if(Info.CouponName=="")
    {
        alert("优惠券名称不能为空");
        return;
    }
    if(Info.CouponType=="")
    {
        alert("优惠券类型不能为空");
        return;
    }
    axios({
        url:'/api/Coupons/Addcoupons',
        method:'post',
        data:Info
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1)
        {
            alert("优惠券已存在");
            return;
        }
        else if(res.data>0)
        {
            alert("添加成功");
            router.push('/couponslist');
        }
        else{
            alert("添加失败");
            return;
        }
    })
}
</script>

<style scoped>

</style>